package com.zzx.bms.controller;

import com.zzx.bms.domain.Borrow;
import com.zzx.bms.service.IBorrowService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by SamZhao on 2016/12/28.
 */
@Controller
@RequestMapping("/borrow")
public class BorrowController {

    private static Logger logger = Logger.getLogger(BorrowController.class);

    @Autowired
    private IBorrowService borrowService;

    @RequestMapping("/checkBorrowOut")
    public @ResponseBody String checkBorrowOut(String bookId, String userId, String userNumber, String bookType) throws Exception {
        int flag = borrowService.checkBorrowOut(bookId,userId,userNumber,bookType);
        return String.valueOf(flag);
    }

    @RequestMapping("/checkBorrowBack")
    public @ResponseBody String checkBorrowBack(String bookId, String userId, String userNumber, String bookType) throws Exception {
        int flag = borrowService.checkBorrowBack(bookId,userId,userNumber,bookType);
        return String.valueOf(flag);
    }

    @RequestMapping("/saveBorrowOut")
    public @ResponseBody String saveBorrowOut(String bookId, String userId, String userNumber, String bookType) throws Exception {
        int flag = borrowService.saveBorrowOut(bookId,userId,userNumber,bookType);
        return String.valueOf(flag);
    }

    @RequestMapping("/saveBorrowBack")
    public @ResponseBody String saveBorrowBack(String bookId, String userId, String userNumber, String bookType) throws Exception {
        int flag = borrowService.saveBorrowBack(bookId,userId,userNumber,bookType);
        return String.valueOf(flag);
    }

    @RequestMapping("/list")
    public String roleList(Borrow role, Model model) throws Exception {

        List<Borrow> borlist = borrowService.findAllBorrowList();
        model.addAttribute("borlist", borlist);

        return "borrow/borrowList";
    }

}
